﻿using MvvmCross.Core.ViewModels;
using Sidvall.IdentityManager.UI.Messaging;
using Sidvall.UI.Messaging;
using System.Windows.Input;

namespace Sidvall.IdentityManager.UI.ViewModels
{
	public class ToolViewModel : Sidvall.IdentityManager.UI.ViewModels.Core.ViewModelBase
	{
		#region Public Members

		#region CanGoBack

		public bool CanGoBack
		{
			get
			{
				return Sidvall.UI.SystemContext.Current.NavigationManager.CanGoBack;
			}
		}

		#endregion
		#region CanGoForward

		public bool CanGoForward
		{
			get
			{
				return Sidvall.UI.SystemContext.Current.NavigationManager.CanGoForward;
			}
		}

		#endregion
		#region CanRefresh

		public bool CanRefresh
		{
			get
			{
				return Sidvall.UI.SystemContext.Current.NavigationManager.CanRefresh;
			}
		}

		#endregion

		// Commands
		#region GoBackCommand

		public ICommand GoBackCommand
		{
			get
			{
				return new MvxCommand(() => GoBack());
			}
		}

		#endregion
		#region GoBack

		public void GoBack()
		{
			ChangePresentation(Sidvall.UI.ViewModels.ViewModelActionType.GoBack);
		}

		#endregion
		#region GoForwardCommand

		public ICommand GoForwardCommand
		{
			get
			{
				return new MvxCommand(() => GoForward());
			}
		}

		#endregion
		#region GoForward

		public void GoForward()
		{
			ChangePresentation(Sidvall.UI.ViewModels.ViewModelActionType.GoForward);
		}

		#endregion
		#region RefreshCommand

		public ICommand RefreshCommand
		{
			get
			{
				return new MvxCommand(() => Refresh());
			}
		}

		#endregion
		#region Refresh

		public void Refresh()
		{
			ChangePresentation(Sidvall.UI.ViewModels.ViewModelActionType.Refresh);
		}

		#endregion
		#region ShowUserConfigurationCommand

		public ICommand ShowUserConfigurationCommand
		{
			get
			{
				return new MvxCommand(() => ShowUserConfiguration());
			}
		}

		#endregion
		#region ShowUserConfiguration

		public void ShowUserConfiguration()
		{
			ShowViewModel<UserConfigurationViewModel>((object)null, true, "CenterContent");
		}

		#endregion
		#region ShowInformationCommand

		public ICommand ShowInformationCommand
		{
			get
			{
				return new MvxCommand(() => ShowInformation());
			}
		}

		#endregion
		#region ShowInformation

		public void ShowInformation()
		{
			ShowViewModel<InformationViewModel>((object)null, true, "CenterContent");
		}

		#endregion

		#region Start

		public override void Start()
		{
			base.Start();
			
			Subscribe<NavigationMessage, ServerManagerMessage>(OnNavigation, OnServerManagerMessage);
			RaiseAllPropertiesChanged();
		}

		#endregion

		#endregion
		#region Private Members

		#region OnNavigation

		private void OnNavigation(NavigationMessage item)
		{
			RaisePropertyChanged("CanGoBack");
			RaisePropertyChanged("CanGoForward");
			RaisePropertyChanged("CanRefresh");
		}

		#endregion
		#region OnServerManagerMessage

		private void OnServerManagerMessage(ServerManagerMessage item)
		{
			RaiseAllPropertiesChanged();
		}

		#endregion

		#endregion
		#region Constructors

		public ToolViewModel()
		{
		}

		#endregion
	}
}
